# -*- coding: utf-8 -*-
from __future__ import print_function

from abc import ABCMeta


class AbstractPriceHandler(object):
    """
    PriceHandler是一个基类提供接口给子类实现，行情模块的目的是产生tick事件或bar事件
    推送到事件消息队列中去。实盘的数据取自交易所的行情接口。回测的数据取自本地存储的数据，
    这个根据程序需要去实现子类
    """

    __metaclass__ = ABCMeta

    def unsubscribe_ticker(self, ticker):
        """
        取消对某个交易代码的行情订阅
        """
        try:
            self.tickers.pop(ticker, None)
            self.tickers_data.pop(ticker, None)
        except KeyError:
            print(
                "Could not unsubscribe ticker %s "
                "as it was never subscribed." % ticker
            )


class AbstractTickPriceHandler(AbstractPriceHandler):
    def istick(self):
        return True

    def isbar(self):
        return False

    def get_best_bid_ask(ticker):
        raise NotImplementedError("not Implement get_best_bid_ask")



class AbstractBarPriceHandler(AbstractPriceHandler):
    def istick(self):
        return False

    def isbar(self):
        return True
